package com.common.retrofit;


import com.common.retrofit.entity.resultImpl.CityLocalBean;
import com.common.utils.EmptyUtils;
import com.common.utils.SPUtils;
import com.common.utils.StringUtils;
import com.google.gson.Gson;

/*******************************
 * 数据保存

 * created at 2017/3/14 下午 2:17
 ********************************/
public class DataCenter {
    public CityLocalBean getCityLocalBean() {
        return cityLocalBean;
    }

    public void setCityLocalBean(CityLocalBean cityLocalBean) {
        this.cityLocalBean = cityLocalBean;
    }

    private CityLocalBean cityLocalBean;           // 本地地理位置获取
    public static int type;
    private static DataCenter instance = null;
    public static final String SHOPID = "SHOPID";                  // 店铺id
    public static final String EASEUSERNAME = "EASEUSERNAME";      // 环信账号
    public static final String USERID = "USERID";                  // 当前用户id
    public static final String TOKEN = "TOKEN";                    // 用户令牌
    public static final String ISFIRST = "ISFIRST";                // 是否首次启动保存key
    public static final String USERBENA = "USERBENA";              // 用户详细信息保存key

    public static final String USERTYPE = "1";



    // 用户TOKEN保存到本地
    private String token;      // 用户令牌
    private int shopId;     // 店铺id
    private int userId;     // 当前登录人id
    private String easeUserName;      // 环信账号

    private DataCenter() {
        instance = this;
    }

    public static void initDataCenter() {
        if (null == instance) {
            new DataCenter();
        }
    }

    public static DataCenter getInstance() {
        if (instance == null) {
            synchronized (DataCenter.class) {
                if (instance == null) {
                    instance = new DataCenter();
                }
            }
        }
        return instance;
    }


    /**
     * 清空登录信息
     */
    public static void deleteLoginDataInfo() {
        DataCenter.getInstance().setToken("");
        SPUtils.setShareString(DataCenter.TOKEN, "");
        DataCenter.getInstance().setEaseUserName("");
        SPUtils.setShareString(DataCenter.EASEUSERNAME, "");

        SPUtils.setShareJson(DataCenter.USERBENA, "");
    }

    public String getEaseUserName() {
        return EmptyUtils.isEmpty(easeUserName) ? SPUtils.getShareString(DataCenter.EASEUSERNAME) : StringUtils.nullToStr(easeUserName);
    }

    public void setEaseUserName(String easeUserName) {
        this.easeUserName = StringUtils.nullToStr(easeUserName);
    }


    public void setShopId(int shopId) {
        this.shopId = shopId;
    }




    public void setUserId(int userId) {
        this.userId = userId;
    }

    public String getToken() {
        return EmptyUtils.isEmpty(token) ? SPUtils.getShareString(DataCenter.TOKEN) : StringUtils.nullToStr(token);
    }

    public void setToken(String token) {
        this.token = StringUtils.nullToStr(token);
    }


}